package com.mazaiting.manager.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.mazaiting.common.core.ex.exceptions.BaseException;
import com.mazaiting.manager.domain.entity.SysUserRole;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * sys_user_role 服务类
 * </p>
 *
 * @author 党海亮
 * @since 2022-03-29
 */
public interface ISysUserRoleService extends IService<SysUserRole> {

    /**
     * 保存用户角色关系
     *
     * @param userId  用户 ID
     * @param roleIds 角色 ID 列表
     * @return true: 保存成功; false: 失败
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    boolean saveUserRoles(Long userId, List<Long> roleIds) throws BaseException;

    /**
     * 根据用户 ID 删除关系
     *
     * @param userId 用户id
     * @return true: 删除成功; false: 删除失败
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.MANDATORY)
    boolean deleteByUserId(Long userId) throws BaseException;

    /**
     * 根据用户 ID 列表删除用户角色关系
     * @param userIdList 用户 ID 列表
     * @return true: 删除成功; false: 删除失败
     */
    boolean deleteByUserIds(List<Long> userIdList) throws BaseException;
}
